package com.servo.controller;


import com.servo.model.CategoryDO;
import com.servo.service.CategoryService;
import com.servo.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author fwj
 * @since 2022-01-07
 */
@Api(tags = "分类api")
@RestController
@RequestMapping("/api/category/")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @ApiOperation("分类树结构")
    @GetMapping("listWithTree")
    public JsonData listWithTree() {
        return categoryService.listWithTree();
    }

    @ApiOperation("添加分类")
    @PostMapping("save")
    public JsonData save(@RequestBody CategoryDO categoryDO) {
        return categoryService.save(categoryDO);
    }

    @ApiOperation("修改分类")
    @PutMapping("update")
    public JsonData update(@RequestBody CategoryDO categoryDO) {
        return categoryService.update(categoryDO);
    }

    @ApiOperation("根据id获取")
    @GetMapping("getById/{id}")
    public JsonData getById(@PathVariable("id")Long id){
        return categoryService.getById(id);
    }

}

